package com.hundsun.yr.universal.p2p.ui.view;

import android.app.Activity;
import android.content.Context;

import com.hundsun.yr.universal.library.common.KeyBoardUtils;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog.HSDialogOnItemClickListener;
import com.hundsun.yr.universal.library.view.hsdialog.HSDialog.Style;
import com.hundsun.yr.universal.p2p.bean.enums.base.LabelEnum;

import java.util.List;
/**
 * 
 * @author tonglj
 *	选择项
 */
public class HSActionSheet  {
	/**
	 * 标题
	 */
	private String title;
	
	private Context mContext;
	private HSDialogOnItemClickListener listener;
	private String[] items;
	private HSDialog dialog;
	
	private String cancel = "取消";
	
	public HSActionSheet(Context cocntext){
		mContext = cocntext;
	}
	public HSActionSheet(Context cocntext,String title){
		mContext = cocntext;
		this.title = title;
	}
	
	/**
	 * 显示dialog
	 * @return
	 */
	public HSDialog show(){
		dialog = new HSDialog(title,null,cancel,null,items,mContext,Style.ActionSheet,listener);
		dialog.show();
		KeyBoardUtils.getInstance((Activity) mContext).hide();
		return dialog;
	}
	
	
	
	/**
	 * 设置监听
	 * @param listener
	 */
	public void setItemClickListener(HSDialogOnItemClickListener listener){
		this.listener = listener;
	}
	/**
	 * 设置选项
	 * @param datas
	 */
	public void setItems(String[] datas){
		this.items = datas;
	}
	/**
	 * 
	 * @param datas
	 */
	@SuppressWarnings("static-access")
	public void setItems(List<LabelEnum> datas,boolean isDefaultTitle){
		int length = datas.size();
		String[] lables = new String[length];
		for (int i = 0; i < length; i++) {
			lables[i] = datas.get(i).getLable();
		}
		this.items = lables;
		if(isDefaultTitle){
			this.title = datas.get(0).getTitle();
		}
	}
}
